home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ccdemo / ccdemo.tx_ / ccdemo.tx
Encoding:
Text File  |  1998-11-02  |  2.9 KB  |  64 lines

  1. CHOOSECOLOR API DEMO ⌐ Mike McGrath(UK)1998  emailto:mikem@clara.net
  2. ====================================================================
  3.  
  4. This demonstration illustrates the steps required by the windows color dialog box in allowing the
  5. user to select a color. These steps are normally automated but the demo now requires them  to be
  6. taken manually in order to understand them fully.
  7.  
  8. DECLARATION:
  9. ============
  10. Declare Function ChooseColor Lib "comdlg32" Alias"ChooseColorA" _
  11.  (pChoosecolor As ChooseColor)As Long
  12.  
  13. VARIABLE STRUCTURE:
  14. ===================
  15. Type ChooseColor 
  16.   lStructSize As Long (length of variable)
  17.   hwndOwner As Long   (handle of calling window)
  18.   hInstance As Long   (not used in demo)
  19.   rgbResult As Long   (color from 0 to 16777215)
  20.   lpCustColors As String (value of custom color)
  21.   flags As Long       (any required flags)
  22.   lCustData As Long   (not used in demo)
  23.   lpfnHook As Long    (not used in demo)
  24.   lpTemplateName As String  (not used in demo)
  25. End Type
  26.  
  27. FLAGS:
  28. ======
  29. Const CC_RGBINIT = &H1          (open colordialog with selected color set to rgbResult value)
  30. Const CC_FULLOPEN = &H2         (open colordialog with custom colors already opened)
  31. Const CC_PREVENTFULLOPEN = &H4  (disable the button which opens custom colors)
  32. Const CC_SHOWHELP = &H8         (enable the help button)
  33. Const CC_SOLIDCOLOR = &H80      (return equivalent selected color, for 256 colors or below)
  34. Const CC_ANYCOLOR = &H100       (return the actual selected color, for 256 colors or below)
  35.  
  36. VARIABLES:
  37. ==========
  38. Dim CustomColors() As Byte       (establish array for custom colors) 
  39. Dim MyColor As ChooseColor       (to pass selection to variable type structure)
  40.  
  41. EXECUTION:
  42. ==========
  43. MyColor.flags =CC_ANYCOLOR         (set flags,"OR" for joint flags)
  44. MyColor.lStructSize = Len(MyColor) (set size of variable structure) 
  45. MyColor.hwndOwner = Form1.hWnd     (get handle of calling window)
  46. ReDim CustomColor(64) As Byte        (make array for custom colors)                     
  47. MyColor.lpCustColors = StrConv(CustomColor, vbUnicode) (convert array to string for api)
  48. x = ChooseColor(MyColor)       (call ChooseColor function)
  49. CustomColor=StrConv(MyColor.lpCustColors,vbFromUnicode) (convert array back from api)                          
  50. MyColor.rgbResult                  (returns chosen color to control)
  51.  
  52. NOTES:
  53. ======
  54. To see purpose of CC_ANYCOLOR and CC_SOLIDCOLOR set screen color depth to 256 colors or less.
  55. CustomColor byte array stores selected color in rgb format using 4bytes for each selection.
  56. eg. Byte0(red)=012  Byte1(green)=123  Byte2(blue)=234  Byte3=0 (4th byte is always zero).
  57. This array must be converted to unicode format before passing to ChooseColor.
  58.  
  59. CHOOSECOLOR API DEMO ⌐ Mike McGrath(UK)1998              emailto:mikem@clara.net
  60. Permission is required for anything other than private use of this software and no liability 
  61. whatsoever will be accepted in connection with its use.  
  62.  
  63.  
  64.